package com.jiazhong.boot.mvc.controller;

import com.jiazhong.boot.commons.util.JsonResult;
import com.jiazhong.boot.commons.util.ResultTool;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

// Restful风格
@RestController
@RequestMapping("/sixth")
public class SixthController {

    // http://localhost:8001/sixth
    @GetMapping
    public JsonResult a() {
        return ResultTool.success("a");
    }

    // 过去：http://localhost:8001/sixth/b?name=admin
    // 现在：http://localhost:8001/sixth/b/admin
    @GetMapping("/b/{name}")
    public JsonResult b(@PathVariable("name") String name) {
        return ResultTool.success(name);
    }

    @GetMapping("/c/{name}/{age}")
    public JsonResult c(@PathVariable("name") String name, @PathVariable("age") int age) {
        return ResultTool.success(name + ".." + age);
    }
    // 不在另外演示post、put以及delete
}
